

/***********************************************************************/
/* INCLUDE FILE NAME:                                                  */
/* ==================                                                  */
/*                                                                     */
/* Author:                                                             */
/*                                                                     */
/* COMMENT:                                                            */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

#ifndef P_STATUS_H
#define P_STATUS_H

/* to include the test script executor in p_test, set this define to anything */
#undef INCLUDE_PNEU_TEST 

#define NUM_STORED_READINGS 20

  /* enable calculation intensive monitoring for column pressure compensation */

/*****************************/
/*  Signal Sources           */
/*****************************/

#define FI_PRES_SETPT_SIGNAL_SOURCE       ((U_INT32 *)&Inst_Status.Pneu.Frnt_Inlet.Delayed_NTP_Inlet_Pres_Setpt      )
#define FI_FLOW_SETPT_SIGNAL_SOURCE       ((U_INT32 *)&Inst_Status.Pneu.Frnt_Inlet.Delayed_NTP_Inlet_Flow_Setpt      )

#define BI_PRES_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Back_Inlet.NTP_Adjusted_Current_Pressure     )
#define BI_FLOW_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Back_Inlet.NTP_Adjusted_Current_Flow         )

#define BI_PRES_SETPT_SIGNAL_SOURCE       ((U_INT32 *)&Inst_Status.Pneu.Back_Inlet.Delayed_NTP_Inlet_Pres_Setpt      )
#define BI_FLOW_SETPT_SIGNAL_SOURCE       ((U_INT32 *)&Inst_Status.Pneu.Back_Inlet.Delayed_NTP_Inlet_Flow_Setpt      )

#define FI_PRES_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Frnt_Inlet.NTP_Adjusted_Current_Pressure     )
#define FI_FLOW_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Frnt_Inlet.NTP_Adjusted_Current_Flow         )

#define C1_PRES_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Column_1.NTP_Adjusted_Current_Pressure       )
#define C1_FLOW_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Column_1.NTP_Adjusted_Current_Flow           )

#define C2_PRES_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Column_2.NTP_Adjusted_Current_Pressure       )
#define C2_FLOW_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Column_2.NTP_Adjusted_Current_Flow           )

#define FD_F_PRES_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_1.Pres_Setpt               )
#define FD_F_PRES_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_1.Current_Pres             )

#define FD_F_FLOW_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_1.Filtered_Flow_Setpt      )
#define FD_F_FLOW_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_1.Filtered_Current_Flow    )

#define FD_U_PRES_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_2.Pres_Setpt               )
#define FD_U_PRES_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_2.Current_Pres             )

#define FD_U_FLOW_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_2.Filtered_Flow_Setpt      )
#define FD_U_FLOW_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_2.Filtered_Current_Flow    )

#define FD_M_PRES_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_3.Pres_Setpt               )
#define FD_M_PRES_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_3.Current_Pres             )

#define FD_M_FLOW_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_3.Filtered_Flow_Setpt      )
#define FD_M_FLOW_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Frnt_Detector.Gas_3.Filtered_Current_Flow    )

#define BD_F_PRES_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_1.Pres_Setpt               )
#define BD_F_PRES_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_1.Current_Pres             )

#define BD_F_FLOW_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_1.Filtered_Flow_Setpt      )
#define BD_F_FLOW_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_1.Filtered_Current_Flow    )

#define BD_U_PRES_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_2.Pres_Setpt               )
#define BD_U_PRES_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_2.Current_Pres             )

#define BD_U_FLOW_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_2.Filtered_Flow_Setpt      )
#define BD_U_FLOW_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_2.Filtered_Current_Flow    )

#define BD_M_PRES_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_3.Pres_Setpt               )
#define BD_M_PRES_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_3.Current_Pres             )

#define BD_M_FLOW_SETPT_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_3.Filtered_Flow_Setpt      )
#define BD_M_FLOW_ACTUAL_SIGNAL_SOURCE    ((U_INT32 *)&Inst_Status.Pneu.Back_Detector.Gas_3.Filtered_Current_Flow    )

#define A3_PRES_SETPT_SIGNAL_SOURCE       ((U_INT32 *)&Inst_Status.Pneu.Aux.Aux_3.Delayed_NTP_Aux_Pres_Setpt         )
#define A3_PRES_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Aux.Aux_3.NTP_Adjusted_Current_Pressure      )

#define A4_PRES_SETPT_SIGNAL_SOURCE       ((U_INT32 *)&Inst_Status.Pneu.Aux.Aux_4.Delayed_NTP_Aux_Pres_Setpt         )
#define A4_PRES_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Aux.Aux_4.NTP_Adjusted_Current_Pressure      )

#define A5_PRES_SETPT_SIGNAL_SOURCE       ((U_INT32 *)&Inst_Status.Pneu.Aux.Aux_5.Delayed_NTP_Aux_Pres_Setpt         )
#define A5_PRES_ACTUAL_SIGNAL_SOURCE      ((U_INT32 *)&Inst_Status.Pneu.Aux.Aux_5.NTP_Adjusted_Current_Pressure      )

#define ATMOSPHERIC_PRES_SIGNAL_SOURCE    ((U_INT32 *)&Atmospheric_Pressure.Dcm2_80                                  )
#define ATMOSPHERIC_PRES_SOURCE_SCALING   80

#define FI_MODULE_TEMP_SIGNAL_SOURCE      ((U_INT32 *)&Frnt_Inlet_Tcomp_Tables.Thermistor.Module_Temperature         )
#define BI_MODULE_TEMP_SIGNAL_SOURCE      ((U_INT32 *)&Back_Inlet_Tcomp_Tables.Thermistor.Module_Temperature         )
#define FD_MODULE_TEMP_SIGNAL_SOURCE      ((U_INT32 *)&Frnt_Det_Tcomp_Tables.Thermistor.Module_Temperature           )
#define BD_MODULE_TEMP_SIGNAL_SOURCE      ((U_INT32 *)&Back_Det_Tcomp_Tables.Thermistor.Module_Temperature           )
#define PA_MODULE_TEMP_SIGNAL_SOURCE      ((U_INT32 *)&Pneu_Aux_Tcomp_Tables.Thermistor.Module_Temperature           )

#define PNEU_10_VOLT_SIGNAL_SOURCE        ((U_INT32 *)&Inst_Status.Pneu.Environment.Ten_Volts                        )
#define PNEU_ADC_OFFSET_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Environment.ADC_Offset_Volts                 )

#define FI_FS_GAS_DRIVE_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Environment.Frnt_Inlet_Gas                   )
#define BI_FS_GAS_DRIVE_SIGNAL_SOURCE     ((U_INT32 *)&Inst_Status.Pneu.Environment.Back_Inlet_Gas                   )

#define FRIT_MAX_FLOW                     Tcomp_Tables->Frit.Parms.Max_Flow                                            
#define Desired_Pres                      Desired_Flow
#define Delayed_Det_Pres_Setpt            Filtered_Flow_Setpt

/*****************************/
/* Foreground Multiplexing   */
/*****************************/

typedef enum { DO_FRNT_INLET, DO_BACK_INLET, DO_FRNT_DET, DO_BACK_DET, DO_AUXES } DO_WHAT;

/*****************************/
/* det module interfacing    */
/*****************************/

#define DET_POSITION(status)  (((status)->Position == FRNT_DET ) ? FRONT : BACK )


/*****************************/
/* Readiness Definitions     */
/*****************************/


  /* timing characteristics for inlet readiness */

  /* how often is readiness checked ? */
#define READY_EVAL_PERIOD    100   /* MSec, 50Hz/5 = 10 Hz, 100mSec */

#define START_TIMEOUT       12000  /* msec waiting for injection pulse to settle out */  /* was 6000 */
#define EVENT_TIMEOUT       12000  /* msec waiting for not ready events to settle out */ /* was 5000 */

  /* how many times before declaring truely not ready ? */
#define PRES_NOT_READY_DELAY  10   /* not ready eval tics before truely declaring inlet pres not ready  */
#define FLOW_NOT_READY_DELAY  10   /* not ready eval tics before truely declaring inlet flow not ready  */
#define DET_NOT_READY_DELAY   10   /* not ready eval tics before truely declaring inlet flow not ready  */
#define IGNORE_READY_DELAY    20   /* num of continuous ready tics before we exit the ignore state      */

                                      /* REPORTED */
typedef enum { NOT_IN_CONTROL_,       /* not ready                                                                */  
               READY_DELAY,           /* not ready     counting equib timer before declaring readiness            */
               FORCED_NOT_READY,      /* not ready     condition forcing not ready (gas change, limits reached)   */

               IN_CONTROL_,           /*  ready                                                                   */
               NOT_READY_DELAY,       /*  ready        counting sequential not readys before declaring not ready  */
               IGNORE_IF_NOT_READY,   /*  ready        physical event may cause not ready which should be ignored */
               IGNORING_NOT_READY,    /*  ready        ignoring not ready due to some physical event.             */
               NOT_CONTROLING         /*  ready        inlet is not being used, so can't be not ready             */
 
             } READINESS_STATE;


typedef struct {  U_INT32           Setpt;
                  U_INT32           Actual;
                  INT32             Difference;
                  INT32             Bound;

                  BIT8              Controlled;
                  BIT8              In_Bounds;
                  BIT8              Capped;
                  BIT8              Temp_Exceeds_CF_Max;

                  READINESS_STATE   State;
                  U_INT16           Tic_Counter;
                  U_INT16           Timeout;
                  U_INT16           Secondary_Timer;
                  U_INT16           Not_Ready_Delay;
                  BIT8              Reported_Ready;
               
               } HERE_I_COME, *pHERE_I_COME; 


typedef struct {

                 /* event flags */
               BIT8              Start;
               BIT8              Purge_On;
               BIT8              Purge_Off;
               BIT8              Pulse_On;
               BIT8              Saver_On;
               BIT8              Pulse_Off;
               BIT8              Saver_Off;
               BIT8              Inlet_On;
               BIT8              SVent_On;
               BIT8              SVent_Off;
               BIT8              VI_Flow_On;
               BIT8              VI_Flow_Off;

                 /* state flag  */
               BIT8              InjWoPres;  /* Inject With out Pressure; used by       */
                                             /*  1/ Solvent Vent w/ Press=0 & Flow != 0 */


                 /* forced not ready flags */
               BIT8              Setpt_Change;
               BIT8              FS_Auto_Zero;

               HERE_I_COME       Flow;
               HERE_I_COME       Pres;

               /* used to signal that splitless is important */
               BIT8              Controlling_Purge;

               } READY_OR_NOT;

           

typedef struct {
                 /* event flags */


                 /* forced not ready flags */
               BIT8              Fuel_Capped;
               BIT8              Util_Capped;
               BIT8              Mug_Capped;
               BIT8              Fuel_Setpt_Change;
               BIT8              Util_Setpt_Change;
               BIT8              Mug_Setpt_Change;
               BIT8              Pres1_Setpt_Change;
               BIT8              Pres2_Setpt_Change;
               BIT8              Pres3_Setpt_Change;
               BIT8              Setpt_Change;

               HERE_I_COME       Fuel_Pres;
               HERE_I_COME       Util_Pres;
               HERE_I_COME       Mug_Pres;

               HERE_I_COME       Fuel_Flow;
               HERE_I_COME       Util_Flow;
               HERE_I_COME       Mug_Flow;

               } DET_READY_STRUCT;


typedef struct {

                 /* ignore flags */
               BIT8              Time_Program_Change;

                 /* forced not ready flags */
               BIT8              Setpt_Change;
               BIT8              Capped;
               BIT8              Start;
               BIT8              On;
               BIT8              Temp_Exceeds_CF_Max;

               HERE_I_COME       Pres;

               } AUX_READY_STRUCT;

           

/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/


/*****************************/
/*   MACROS                  */
/*****************************/

#define NUM_PNEU_CHANNELS            13
#define NUM_ENV_CHANNELS             11

#define REF_TABLE_SIZE          (256+1)
#define CORRECT_TABLE_SIZE           32

#define INLET_CORRECT_TABLE_SIZE     33






/****************************************************************/
/****************************************************************/
/**                                                            **/
/**     Temp Compensated of sensors                            **/
/**                                                            **/
/****************************************************************/
/****************************************************************/



typedef struct { 
                 U_INT16 V_25C;
                 INT16   dV;
                 INT16   dT;
               } THERMISTOR_PARMS, *pTHERMISTOR_PARMS;


typedef struct {
                 U_INT16 Span;
                 U_INT16 Range;
                 U_INT16 Offset;
                 INT16   dSpan_dT;
                 INT16   dOffset_dT;
               } PRES_SENSOR_PARMS, *pPRES_SENSOR_PARMS;


typedef struct {
                 U_INT16 Reference_Temp;

                 U_INT16  Offset;         /*  @ 25C, 1V = 16384 */
#if 0
                 U_INT16  Offset_Offset;  /* to allow zero to begin on a volt table boundry */
#endif

                 float  Alpha_Low;    /* scaled by 16384 */
                 float  Alpha_High;   /* scaled by 16384 */

                 float  Beta_Low;     /* scaled by 1E6   */
                 float  Beta_High;    /* scaled by 1E6   */

                 float  High_Flow;    /* flow when high terms kick in */

                 float    dAlpha_dT;    /*  */
                 float    dBeta_dT;     /*  */
                 float    dOffset_dT;   /*  */

                 INT16    delta_offset_delta_t;
                
                 U_INT16  High_Volts;   /* generated from high flow */

                 U_INT32  Max_Flow;

               } FLOW_SENSOR_PARMS, *pFLOW_SENSOR_PARMS;


typedef struct { 
                 U_INT32  frit_1;
                 U_INT32  frit_2;

                 U_INT32  Max_Flow;  /* the currently used max flow */

                 float    Alpha;
                 float    Beta;

                 U_INT32  Max_Gas_Flow_Rates [ UNKNOWN_GAS ];  /* saved det gas max flows reported to wkstation */

               } FRIT_PARMS, *pFRIT_PARMS;


/*************************************************************/
/*************************************************************/
/**                                                         **/
/**  Flow to Volts/Pres conversion masks                    **/
/**                                                         **/
/*************************************************************/
/*************************************************************/

typedef struct { 
                 THERMISTOR_PARMS   Parms;
                 U_INT16            Volts_To_Temp[ 257 ];
                 U_INT32            Temp_Filter;
                 U_INT16            Module_Temperature;

               } THERMISTOR_STRUCT, *pTHERMISTOR_STRUCT;


typedef struct {
                 PRES_SENSOR_PARMS  Parms;

                 BIT8      Temp_Comp_Enabled;

                 /* for debug display */

                 U_INT16  Pres_Setpt;               U_INT16  Pres_Actual;
                 U_INT16  Pres_Volts_Setpt;         U_INT16  Pres_Volts_Actual;
                 INT16    Pres_dV_Setpt;            INT16    Pres_dV_Actual;
                 U_INT16  Pres_Adc_Setpt;           U_INT16  Pres_Adc_Actual;

               } PRES_SENSOR_STRUCT, *pPRES_SENSOR_STRUCT;



typedef struct {
                 FLOW_SENSOR_PARMS Parms;

                 U_INT32  Mask;
                 U_INT16  Shift_Value;
                 U_INT32  Entry_Spacing;  /* mL/min between entries */
                 U_INT16  Num_Entries;

                 U_INT32  Comp_Mask;
                 U_INT16  Comp_Shift;
                 U_INT32  Comp_Entry_Spacing;

                 U_INT16  Flow_To_Volts [ REF_TABLE_SIZE +1 ];
                 U_INT32  Volts_To_Flow [ REF_TABLE_SIZE +1 ];

                 INT16    dV_dT [ INLET_CORRECT_TABLE_SIZE +1 ];

                 BIT8      Temp_Comp_Enabled;

                 /* for debug display */

                 U_INT32  Flow_Setpt;               U_INT32  Flow_Actual;
                 U_INT16  Volts_Setpt;              U_INT16  Volts_Actual;
                 INT16    dV_Setpt;                 INT16    dV_Actual;
                 U_INT16  Total_Volts_Setpt;        U_INT16  Total_Volts_Actual;

               } FLOW_SENSOR_STRUCT, *pFLOW_SENSOR_STRUCT;

typedef struct {
                   struct {
                           U_INT32 Purge_Flow;
                           INT32   dFlow_dPres;
                          } Parms[ 4 ];
                  

               }   PURGE_REG_STRUCT, *pPURGE_REG_STRUCT;


typedef struct {
                   FRIT_PARMS        Parms;

                   U_INT32  Mask;
                   U_INT16  Shift_Value;

                   U_INT32  Step_Rate;
                   U_INT16  Num_Entries;

                   BIT8      Temp_Comp_Enabled;

                    /*     Reference Tables     */
                    /* Flow->Pres    Pres->Flow */

                   U_INT16 Flow_To_Pres  [ REF_TABLE_SIZE ];
                   U_INT32 Pres_To_Flow  [ REF_TABLE_SIZE ];

                   /* Setpt Correction Tables */

                   INT32   Setpt_Temp_Correct_Per_T_IU[ CORRECT_TABLE_SIZE ];
                   INT32   Setpt_Pres_Correct_Per_P_IU[ CORRECT_TABLE_SIZE ];

                   /* for debug display */

                   U_INT16 Pres_Setpt;     U_INT16 Pres_Actual;
                   U_INT16 UPres_Setpt;    U_INT16 UPres_Actual;
                   INT16   TCorr_Setpt;    INT16   TCorr_Actual;
                   INT16   PCorr_Setpt;    INT16   PCorr_Actual;

               } FRIT_STRUCT, *pFRIT_STRUCT;


/*******************************************************************************/
/*******************************************************************************/


typedef struct {
                  FLOW_SENSOR_STRUCT Flow_Sensor;
                  PRES_SENSOR_STRUCT Pres_Sensor;
                  PURGE_REG_STRUCT   Purge_Regulator;
                  THERMISTOR_STRUCT  Thermistor;

               } INLET_TCOMP_STRUCT, *pINLET_TCOMP_STRUCT;


typedef struct {
                  FRIT_STRUCT        Frit;
                  PRES_SENSOR_STRUCT Pres_Sensor;

               } DET_GAS_TABLE, *pDET_GAS_TABLE;


typedef struct {
                  DET_GAS_TABLE   Fuel;
                  DET_GAS_TABLE   Util;
                  DET_GAS_TABLE   Mug;

                  THERMISTOR_STRUCT  Thermistor;

               } DETECTOR_TCOMP_STRUCT, *pDETECTOR_TCOMP_STRUCT;


typedef struct {
                  PRES_SENSOR_STRUCT  Aux_3;
                  PRES_SENSOR_STRUCT  Aux_4;
                  PRES_SENSOR_STRUCT  Aux_5;

                  THERMISTOR_STRUCT  Thermistor;

               } AUX_TCOMP_STRUCT, *pAUX_TCOMP_STRUCT;


 /***************************************/
 /**  User Calibration of Sensors      **/
 /***************************************/

typedef enum { FACTORY            = 0,
               USER_ENABLED       = 1, 
               USER_DISABLED      = 2,
               INVALID_USER_CALIB = 3  } CALIB_STATE;

typedef struct {  INT16   Offset;
                  U_INT16 Gain;      /* adjusted by 16384 */
                  U_INT16 Value;
               } SENSOR_CALIB;

typedef struct {    INT16       Offset;
                    U_INT16     Gain;
                    U_INT16     Flow;
               }  DET_GAS_CALIB, *pDET_GAS_CALIB;


typedef struct { SENSOR_CALIB Pos_1;
                 SENSOR_CALIB Pos_2;
                 SENSOR_CALIB Pos_3;
                 DATETIME     Date;
               } *pCALIB_STRUCT, CALIB_STRUCT;



typedef struct { U_INT16 Calib_Pressure;
                 U_INT16 Calib_Flow;
                 INT16   P_Sensor_Gain;              /* adjusted by 65536 */
                 INT16   P_Sensor_Offset;
                 INT16   F_Sensor_Gain;              /* adjusted by 65536 */
                 INT32   F_Sensor_Offset;            /* adjusted by 256   */
                 DATETIME Calib_Date;
                 CALIB_STATE Calib_State;
               } INLET_CALIB, *pINLET_CALIB;




 /***************************************/
 /**         environment               **/
 /***************************************/



typedef struct
        {
      /* dont be confused, these are _only_ voltages from pcb */
      /* these things may be stored elsewhere for usage       */

            U_INT16  Frnt_Inlet_Temp;
            U_INT16  Back_Inlet_Temp;
            U_INT16  Frnt_Det_Temp;
            U_INT16  Back_Det_Temp;
            U_INT16  Aux_Temp;

            U_INT16  Atm_Pres;
            U_INT32  Atm_Pres_Filter;

            U_INT16  Frnt_Inlet_Gas;
            U_INT16  Back_Inlet_Gas;

            U_INT16  ADC_Offset_Volts;
            U_INT16  Ten_Volts;

            U_INT16  Pneu_24_Volts;
            U_INT32  Pneu_24_Volts_Filter;

            /* these are the real corrections */

            U_INT32    ADC_Offset_Filter;
            U_INT32    Ten_Volt_Filter;

            INT16    ADC_Offset;
            INT16    Ten_Volt_Offset;


            INT16    Adc_Gain;
            INT16    True_Adc_Offset;

        } ENV_STRUCT;

 /***************************************/
 /**        eeprom writes              **/
 /***************************************/

typedef enum { WRITE_IDLE = 0, WRITE_NEW_VALUE, WRITE_NEW_CHECKSUM } EEPROM_WRITE_STATE;

typedef struct {
                 EEPROM_WRITE_STATE  Write_Step;
                 U_INT16             Old_Check_Sum;
                 U_INT16             Old_Data_Value;
                 U_INT16             New_Data_Value;
                 U_INT16             Write_Address;
                 U_INT16             New_Check_Sum;

               } EEPROM_WRITE_STRUCT;
 


/****************************************************************/
/****************************************************************/
/**                                                            **/
/**     Status Struct Components                               **/
/**                                                            **/
/****************************************************************/
/****************************************************************/

typedef struct INLET_STATUS_STRUCT
       {

             BIT8       Shutdown;

             U_INT16    P_Sensor_Range;   /* in IU */
             U_INT16    Real_PS_Range;    /* max pressure needed w/atmp comp to maintain range in ntp units */
             U_INT16    Dcm2_Per_IU;
             U_INT32    IU_Scaling;

             BIT8       Has_Column;    /* all columns on this inlet are defined */

             BIT8       Controlled_By_Column; /* subset of Has_Column, based on      */
                                              /* inlet_type, and column control_mode */
                                              /* indicates that the inlet p/f should */
                                              /* come from the column's definition   */

             READY_OR_NOT Ready;

             U_INT16  Setpt_Oven_Temp;
             U_INT16  Actual_Oven_Temp;

             /* * * *   pressures  * * * */

             BIT8     Slam_Pres_Setpt;               /* used to get post and init col values slammed into filters */

             U_INT16  Inlet_Pressure_Setpt;          /* unfiltered, uncorrected (NTP col comp) setpts         */
             U_INT16  Intermediate_Pres;             /* Do NOT USE! simply a temp value between setpt filters */
             U_INT16  Delayed_NTP_Inlet_Pres_Setpt;  /* time delayed inlet pres (NTP) for display             */

             U_INT16  Compensated_Pressure;          /* unfiltered, corrected (not NTP) pressure              */
             U_INT16  Filtered_Inlet_Pressure_Setpt; /* filtered, corrected, calibrated (not NTP) pressure    */
             U_INT16  Delayed_Inlet_Pressure_Setpt;  /* provide an additional filter/delay to simulate        */
                                                     /* the delay experienced by the actual                   */
             /* voltage values to and from pcb */
             U_INT16   Pres_Adc_Setpt;    
             U_INT16   Pres_Adc_Actual;

             /* calculated actuals from voltage */
             U_INT16  Filtered_Current_Pressure;     /* filtered real (not NTP) pressure   */
             U_INT16  NTP_Adjusted_Current_Pressure; /* displayable NTP current pressure   */

             /* * * *   flows  * * * */

             BIT8     Slam_Flow_Setpt;               /* used to get post and init col values slammed into filters */

             U_INT32   Column;
             U_INT32   Septum;
             U_INT32   Split;
             U_INT32   Total;

             U_INT32   Ntp_Split;
             U_INT32   Ntp_Column;
             U_INT32   Ntp_Total;

             U_INT32  Intermediate_Flow_Setpt;
             U_INT32  Delayed_NTP_Inlet_Flow_Setpt;  /* read only by "display" processes; not sent on to plant */
          /* U_INT32  NTP_Adjusted_Flow_Setpt;         deleted; was replaced with Delayed_NTP_Inlet_Flow_Setpt */

             U_INT32  Inlet_Flow_Setpt;              /* real (not ntp) total flow setpt (same a  Total) */
             U_INT32  Filtered_Total_Inlet_Flow_Setpt; 
             U_INT32  Delayed_Total_Flow_Setpt;

             U_INT16   Flow_Adc_Setpt;  
             U_INT16   Flow_Adc_Actual;

             /* calculated actuals from voltage */

             U_INT32  Real_Filtered_Flow;
             U_INT32  Filtered_Current_Total_Flow;
             U_INT32  NTP_Adjusted_Current_Flow;

             U_INT32  Current_Septum_Flow;
             U_INT32  Current_NTP_Column_Flow;
             U_INT32  Current_NTP_Split_Flow;


             BIT8       VI_Flow_Mode;    /* if we are in FWD_FLOW_NO_PRES mode during VI injection */

             BIT8       Inlet_Purge;     /* status of the purge valve(manual), state(epc) */

             BIT8       Pressure_Pulse;  /* if we are in pulsed pressure mode */

             BIT8       Solvent_Vent;    /* we are in the solvent venting mode */

             BIT8       Miser_Mode;
             BIT8       Low_Miser_Flow;  /* miser flow less than desired column flow */

             U_INT16   COC_TEST_VOLTS;

             BIT8      PCB_Inlet_Control_Mode;


             U_INT32  Setpt_Correct_Ratio;
             U_INT32  Actual_Correct_Ratio;

             INLET_CALIB     Calib;

             /* diagnostics */

             BIT8     Diag_Mode_Enabled;
             BIT8     Solenoid_Valve_Enable;

             SOURCE_CONNECTION Position;   /* filled in at poweron to indicate frnt/back */
                                           /* Frnt_Inlet.Position = FRNT_INLET           */
                                           /* Back_Inlet.Position = BACK_INLET           */
             U_INT16   Module_Number;
             BIT8      Something_There;

             pINLET_TCOMP_STRUCT          Tcomp_Tables;

             struct INLET_CONFIG_STRUCT   *Config;
             struct INLET_WKFILE_STRUCT   *Wkfile;


             U_INT8                       JackInTheBoxControlMode;
             U_INT16                      JackInTheBoxControlVolts;

             U_INT32            Flow_Sensor_Zero_State;  /* really ui_err, but would cause an include file dependency */
             U_INT16           Last_Auto_Cal_Offset;

       } INLET_STATUS, *pINLET_STATUS;
         



typedef struct COLUMN_STATUS_STRUCT
       {

            /* incoming setpoint from ramp generator */

             struct {
                   U_INT32         Head_Pressure;
                   U_INT32         Column_V_Flow;
                   U_INT32         Ramp_Flow_Scaling;
                   U_INT16         Ramp_Pres_Scaling;
             } Ramp_Setpt;

             U_INT16    Active_Pressure;  /* used for display, allows pressure pulse overide of setpoint */
             U_INT32    Active_Flow;      /* used for display, allows inlet overide of the desired setpoint */

             U_INT32    Intermediate_Flow;  /* col does the delays for pp column flows, this filters prior to Active_F */

             /* flow pressure setpoints required */
             /* to maintain incoming setpoint    */

             U_INT32     Desired_Head_Pressure;
             U_INT32     Desired_Column_Flow;

             U_INT32     Prev_Setpt;

             /* real values used for control */
             U_INT16     Real_Ref_Pres;
             U_INT32     Real_Ref_Flow;
             U_INT16     Ref_Po;
             U_INT16     Max_Oven_Temp;
             BIT8        Periodic_Update_Request;

             /* calculated actuals for the column */

             U_INT16     Current_Head_Pressure;
             U_INT32     Current_V_Flow;

             U_INT16     NTP_Adjusted_Current_Pressure;
             U_INT32     NTP_Adjusted_Current_Flow;

             /* column's own unique scaling factors (based on column size) */
             /* carefull, these may change on the fly. and are not the     */
             /* same as those used for the inlet, detector, or ramps       */
             U_INT32     Vel_IU_Scaling;
             U_INT32     IU_Scaling;
             U_INT16     Dcm2_Per_IU;  

             /* this is a copy of the source's gas type */
             GAS_TYPE    Gas_Type;

             /* pseudo constants for column calculations */

             U_INT32     C1;  /* outlet velocity  */
             U_INT32     C2;  /* average velocity */
             U_INT32     C3;  /* volumetric flow  */
             U_INT32     C4;  /* mass flow        */

             U_INT8      Position;   /* filled in at poweron to indicate  1 / 2 */
                                     /* Column_1.Position = 1                   */
                                     /* Column_2.Position = 2                   */

             BIT8        Atm_Pres_Comp_Enabled;

             struct COLUMN_CONFIG_STRUCT      *Config;
             struct COLUMN_WKFILE_STRUCT      *Wkfile;

             void /* RAMPINFO */  *Ramp_Info;                     

             U_INT32    NTP_Pres_Setpt;
             U_INT32    NTP_Flow_Setpt;
             U_INT32    NTP_Uavg_Setpt;

             U_INT32        Pres_Setpt;
             U_INT32        Flow_Setpt;
             U_INT32        Uavg_Setpt;

             U_INT32    NTP_Pres_Actual;
             U_INT32    NTP_Flow_Actual;
             U_INT32    NTP_Uavg_Actual;

             U_INT32        Pres_Actual;
             U_INT32        Flow_Actual;
             U_INT32        Uavg_Actual;



        } COLUMN_STATUS, *pCOLUMN_STATUS;





typedef struct 
        {
             BIT8       Shutdown;

             U_INT16    P_Sensor_Range;   /* in IU */
             U_INT16   Dcm2_Per_IU;
             U_INT32   IU_Scaling;

             U_INT16   Equib_Timer;

             ON_OFF    On_Off;          /* used only for ignition of manual detectors */

             U_INT32   Desired_Flow;
             U_INT32   Filtered_Flow_Setpt;

             U_INT16   Pres_Setpt;     /* unfiltered, used for diagnostics only */

             U_INT16   Adc_Setpt;
             U_INT16   Adc_Actual;

             U_INT32   Filtered_Current_Flow;
             U_INT16   Current_Pres;     /* unfiltered, used for diagnostics only */

             DET_GAS_CALIB Calib;
          
             pDET_GAS_TABLE Tcomp_Tables;

             BIT8       Comp_Tables_Ok;

        } DET_GAS, *pDET_GAS;



typedef struct DETECTOR_STATUS_STRUCT
        {
             DET_GAS   Gas_1;
             DET_GAS   Gas_2;
             DET_GAS   Gas_3;

             BIT8       Shutdown;

             U_INT32    IU_Scaling;

             DET_READY_STRUCT Ready;

             BIT8       In_Ignition_Sequence;

             U_INT8     Duty_Cycle;
             U_INT8     Modulated_Gas;

             BIT8       Has_Column;    /* all columns on this det are defined */

             OUTLET_CONNECTION Position;   /* filled in at poweron to indicate frnt/back */
                                           /* Frnt_Detector.Position = FRNT_DET...       */
                                           /* Back_Detector.Position = BACK_DET...       */

             U_INT16 Module_Number;
             BIT8    Something_There;

             pTHERMISTOR_PARMS  Thermistor;

             DATETIME  Calib_Date;
             CALIB_STATE Calib_State;

             struct DETECTOR_CONFIG_STRUCT      *Config;
             struct DETECTOR_WKFILE_STRUCT      *Wkfile;
             pDETECTOR_TCOMP_STRUCT             Tcomp_Tables;

             U_INT32  Min_Gas_2_Flow_Rate ;  /* min flow in IU for EPC_TCD ref gas, else 0.0  */

        } DETECTOR_STATUS, *pDETECTOR_STATUS;





typedef struct AUX_STATUS_STRUCT
        {

            /* incoming setpoint from ramp generator */

             struct {
                   U_INT32         Ramp_Pressure;
                   U_INT16         Ramp_Pres_Scaling;
             } Ramp_Setpt;

             ON_OFF     On_Off;
             BIT8       Shutdown;

             BIT8       Has_Column;
             BIT8       Controlled_By_Column;

             AUX_READY_STRUCT Ready;

             U_INT16  Setpt_Oven_Temp;
             U_INT16  Actual_Oven_Temp;
             U_INT32  Flow_Correct_Ratio;

             /* * * *   pressures  * * * */

             BIT8     Slam_Pres_Setpt;               /* used to get post and init col values slammed into filters */

             U_INT16  Aux_Pressure_Setpt;            /* unfiltered, uncorrected (NTP col comp) setpts         */
             U_INT16  Intermediate_Pres;             /* Do NOT USE! simply a temp value between setpt filters */
             U_INT16  Delayed_NTP_Aux_Pres_Setpt;    /* time delayed inlet pres (NTP) for display             */

             U_INT16  Compensated_Pressure;          /* unfiltered, corrected (not NTP) pressure              */
             U_INT16  Filtered_Aux_Pressure_Setpt;   /* filtered, corrected, calibrated (not NTP) pressure    */
             U_INT16  Delayed_Aux_Pressure_Setpt;    /* provide an additional filter/delay to simulate        */
                                                     /* the delay experienced by the actual                   */
             /* voltage values to and from pcb */
             U_INT16   Adc_Setpt;
             U_INT16   Adc_Actual;

             /* calculated actuals from voltage */
             U_INT16  Filtered_Current_Pressure;     /* filtered real (not NTP) pressure   */
             U_INT16  NTP_Adjusted_Current_Pressure; /* displayable NTP current pressure   */


             U_INT16   Desired_Pressure;  
             U_INT16   Active_Pressure;             /* setpt currently being controlled to */
             U_INT16   Filtered_Pressure_Setpt;


             SOURCE_CONNECTION Position;   /* filled in at poweron to indicate which aux */
                                           /* Aux_3.Position = AUX3                      */
                                           /* Aux_4.Position = AUX4                      */
                                           /* Aux_5.Position = AUX5                      */

             SENSOR_CALIB Calib;

             U_INT16    P_Sensor_Range;   /* in IU */
             U_INT16    Real_PS_Range;    /* max pressure needed w/atmp comp to maintain range in ntp units */
             U_INT16    Dcm2_Per_IU;
 
             U_INT16    Equib_Timer;


             U_INT16 Module_Number;

             struct AUX_CONFIG_STRUCT      *Config;
             struct AUX_WKFILE_STRUCT      *Wkfile;
             void   /* RAMPINFO */         *Ramp_Info;                     

        } AUX_STATUS, *pAUX_STATUS;



typedef struct {
               U_INT16 Module_Number;
               BIT8    Something_There;

               pTHERMISTOR_PARMS  Thermistor;

               DATETIME     Calib_Date;
               CALIB_STATE  Calib_State;

               THERMISTOR_PARMS       Aux;

               AUX_STATUS             Aux_3;
               AUX_STATUS             Aux_4;
               AUX_STATUS             Aux_5;

               pAUX_TCOMP_STRUCT          Tcomp_Tables;

        } AUXILIARY_STATUS, *pAUXILIARY_STATUS;



typedef struct  PNEU_STATUS_STRUCT
        {
               INLET_STATUS           Frnt_Inlet;
               INLET_STATUS           Back_Inlet;

               COLUMN_STATUS          Column_1;
               COLUMN_STATUS          Column_2;

               DETECTOR_STATUS        Frnt_Detector;
               DETECTOR_STATUS        Back_Detector;

               AUXILIARY_STATUS       Aux;

               ENV_STRUCT             Environment;

               RESOURCE               Resource_Lock;

               BIT8                   Pneu_Dsp_Alive;      /* false if PCB declares a fatal error */
               BIT8                   Pneu_Alive;          /* false if 331 declares a fatal error */

               U_INT16                Channels_Reported_Shutdown;  /* all channels currently shutdown. */

               BIT8                   Installing_Method;  /* inhibit foreground and ignore cmds on config errors */

               struct PNEU_CONFIG_STRUCT     *Config;
               struct PNEU_WKFILE_STRUCT     *Wkfile;


       /* minor status values for display, not used for control */

               U_INT16                Last_Shutdown_Mask;         
               U_INT16                Restarted_Channel_Mask;
               U_INT16                Poweron_Selftest_Return;
               U_INT16                Last_Pcb_Error;


       /* support of duty cycle control and monitoring */

               U_INT16                Duty_Cycle_Setpts  [ NUM_PNEU_CHANNELS ];
               U_INT16                Actual_Duty_Cycles [ NUM_PNEU_CHANNELS ];

    
       /* load monitoring values */

               U_INT32           Avg_Ctrl_Time;
               U_INT32           Peak_Ctrl_Time;
               
               U_INT32           Avg_Disp_Time;
               U_INT32           Peak_Disp_Time;

               BIT8              Block_Foreground_Interrupts;

       /* noise monitoring values */


               U_INT16           Raw_Rdg_Index;
               U_INT16           Raw_Readings [ NUM_STORED_READINGS ] [ NUM_PNEU_CHANNELS ];

               U_INT16           RMS_Counts;                          /* tics expired in current interval */
               U_INT16           MIN          [ NUM_PNEU_CHANNELS ];  /* min value seen over rms interval   */
               U_INT16           MAX          [ NUM_PNEU_CHANNELS ];  /* max value seen over rms interval   */
               U_INT32           Avg_Filters  [ NUM_PNEU_CHANNELS ];  /* sum of values seen in rms interval */
               U_INT16           ENV_MIN      [ NUM_ENV_CHANNELS  ];  /* min value seen over rms interval   */
               U_INT16           ENV_MAX      [ NUM_ENV_CHANNELS  ];  /* max value seen over rum interval   */
               U_INT32           Env_Filters  [ NUM_ENV_CHANNELS  ];  /* sum of values seen in rms interval */


                   /* noise monitoring results */

               U_INT16           Stable_Volts [ NUM_PNEU_CHANNELS ];  /* average, adc offset corrected sensor rdgs */
               U_INT16           MAX_MIN      [ NUM_PNEU_CHANNELS ];  /* sensor peak to peak noise counts          */

               U_INT16           Stable_Env   [ NUM_ENV_CHANNELS  ];  /* average, adc offset corrected env rdgs    */
               U_INT16           ENV_MAX_MIN  [ NUM_ENV_CHANNELS  ];  /* environmental sensors pk-pk noise counts  */



        /* timing definitions */

               U_INT16           RMS_Interval;                        /* num ticks defining interval period */

               U_INT16           Environment_Freq; /* Num tics (period) between DutyCycle, Enviroment, Icap commands */

        /* copy of integral sum cap counters */

               U_INT16           Iscc[ NUM_PNEU_CHANNELS ];
               U_INT16           Last_Icap_Ctr;                /* the value of the highest counter after last noise */


        /* module checksums (read at poweron, updated upon writes */

               U_INT16           Module_Cksums[ 5 ];

               BIT8              Halt_On_Error;
               BIT8              Halt_On_Shutdown;
               BIT8              Halt_On_Cksum_Error;


        /* a 50Hz (20mSec) timer used to provide delays for flow sensor auto calibration */

               U_INT16           Auto_Cal_Timer;
               U_INT16           Auto_Cal_Delay;

        /* foreground multiplexing */

               DO_WHAT           What_Now;


        } PNEU_STATUS, *pPNEU_STATUS;



typedef struct
        {
             PNEU_STATUS       Pneu;

        } INST_STATUS;


/****************************************************************/
/****************************************************************/
/**                                                            **/
/**     Atmospheric Pressure                                   **/
/**                                                            **/
/****************************************************************/
/****************************************************************/

typedef struct {
                 U_INT16  Dcm2_80;
                 U_INT16  Dcm2_160;
                 U_INT16  Dcm2_320;

       } ATMOSPHERIC_PRESSURE;



    /*  these have space allocated in glbram/status.h   */

    extern INST_STATUS Inst_Status;

    extern ATMOSPHERIC_PRESSURE Atmospheric_Pressure;


#pragma SECTION DATA=tcomp

extern INLET_TCOMP_STRUCT     Frnt_Inlet_Tcomp_Tables;
extern INLET_TCOMP_STRUCT     Back_Inlet_Tcomp_Tables;
extern DETECTOR_TCOMP_STRUCT  Frnt_Det_Tcomp_Tables;
extern DETECTOR_TCOMP_STRUCT  Back_Det_Tcomp_Tables;
extern AUX_TCOMP_STRUCT       Pneu_Aux_Tcomp_Tables;

#pragma SECTION UNDO



#endif
